package com.credithc.customers.manager.controller;

import com.alibaba.fastjson.JSONObject;
import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.customers.base.ro.CountLoginFlowRo;
import com.credithc.customers.manager.service.IStatisticPushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhukai
 * @date 2019/1/4 17:09
 */
@RestController
@RequestMapping("/api/v0/statistic/customer")
public class StatisticPushController {
    @Autowired
    private  MessageFactory messageFactory;
    @Autowired
    private IStatisticPushService statisticPushService;

    /**
     * @description: 统计登录流水
     * @author: fby
     * @date: 2020/6/9 14:35
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/countLogin")
    public Message countLoginFlow(@RequestParam(name = "productCode", required = false) String productCode,
                                  @RequestParam(name = "cycle", required = false) String cycle,
                                  @RequestParam(name = "productId", required = false) String productId) {
        CountLoginFlowRo ro = new CountLoginFlowRo();
        ro.setCycle(cycle);
        ro.setProductCode(productCode);
        ro.setProductId(productId);
        JSONObject data = statisticPushService.countLoginFlow(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, data);
    }

    /**
     * @description: 统计注册信息
     * @author: fby
     * @date: 2020/6/18 14:15
     * @param: request
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/count")
    public Message countRegister(@RequestParam(name = "productCode", required = false) String productCode,
                                 @RequestParam(name = "cycle", required = false) String cycle,
                                 @RequestParam(name = "productId", required = false) String productId) {
        CountLoginFlowRo ro = new CountLoginFlowRo();
        ro.setCycle(cycle);
        ro.setProductCode(productCode);
        ro.setProductId(productId);
        JSONObject data = statisticPushService.countRegister(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, data);
    }
}
